<?php

namespace app\index\controller;

use think\Controller;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

class Excel extends Controller
{
    //
    public function index(){
        $spreadsheet = new Spreadsheet();
        $sheet = $spreadsheet->getActiveSheet();
        $sheet->setCellValue('A1', 'Hello World AGWGWAGAWGW!');
        $sheet->mergeCells('A1:B1');
        $sheet->getColumnDimension('A')->setWidth(50);;
        $writer = new Xlsx($spreadsheet);
        $writer->save('static/excel/pan.xlsx');
    }
    public  function  pan(){
        $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
        $reader->setReadDataOnly(TRUE);
        $spreadsheet = $reader->load("static/excel/hello world.xlsx");
        $worksheet = $spreadsheet->getActiveSheet();
        foreach ($worksheet->getRowIterator() as $row) {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(FALSE);
            foreach ($cellIterator as $key=>$cell) {
                   echo $key;
                   echo  $cell->getValue().'<br/>';
            }

            }

    }
}
